package TestModel;

import static org.junit.Assert.*;
import java.util.ArrayList;
import org.junit.Test;
import Task28.Command;
import Task28.Model;
import Task28.Result;

public class TestFind {
	Model tester;
	Result result = new Result();
	Command command = new Command();

	public void init() {
		try {
			tester = new Model();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	public void test1() {
		init();
		String[] args = { "C:\\TEST1", "111" };
		command.setNameCommand("find");
		command.setArgs(args);

		try {
			result = tester.getResult(command);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		String sResult = result.getData().get(0);

		assertEquals("Result",
				"111 - Sun Jan 08 18:48:24 MSK 2012 - C:\\TEST1\\111", sResult);
	}

	@Test
	public void test2() {
		init();
		String[] args = { "C:\\TEST1", "Q3.txt" };
		command.setNameCommand("find");
		command.setArgs(args);

		try {
			result = tester.getResult(command);
		} catch (Exception e1) {
			e1.printStackTrace();
		}

		ArrayList<String> trResult = new ArrayList<String>();
		trResult.add("Q3.txt - Sun Jan 08 17:35:59 MSK 2012 - C:\\TEST1\\Q3.txt");
		trResult.add("Q3.txt - Sun Jan 08 17:36:53 MSK 2012 - C:\\TEST1\\0123\\Q3.txt");
		trResult.add("Q3.txt - Sun Jan 08 17:36:53 MSK 2012 - C:\\TEST1\\0123\\newDir2\\Q3.txt");

		assertEquals("Result", trResult, result.getData());
	}

	@Test
	public void test3() {
		init();
		String[] args = { "C:\\TEST1", "Q*.txt" };
		command.setNameCommand("find");
		command.setArgs(args);

		try {
			result = tester.getResult(command);
		} catch (Exception e1) {
			e1.printStackTrace();
		}

		ArrayList<String> trResult = new ArrayList<String>();
		trResult.add("Q3.txt - Sun Jan 08 17:35:59 MSK 2012 - C:\\TEST1\\Q3.txt");
		trResult.add("Q3.txt - Sun Jan 08 17:36:53 MSK 2012 - C:\\TEST1\\0123\\Q3.txt");
		trResult.add("Q3.txt - Sun Jan 08 17:36:53 MSK 2012 - C:\\TEST1\\0123\\newDir2\\Q3.txt");

		assertEquals("Result", trResult, result.getData());
	}

	@Test
	public void test4() {
		init();
		String[] args = { "C:\\TEST1", "111" };
		command.setNameCommand("find");
		command.setArgs(args);

		try {
			result = tester.getResult(command);
		} catch (Exception e1) {
			e1.printStackTrace();
		}

		ArrayList<String> trResult = new ArrayList<String>();
		trResult.add("111 - Sun Jan 08 18:48:24 MSK 2012 - C:\\TEST1\\111");

		assertEquals("Result", trResult, result.getData());
	}

	@Test
	public void testMask1() {
		init();
		String[] args = { "C:\\TEST1", "a*1*" };
		command.setNameCommand("find");
		command.setArgs(args);

		try {
			result = tester.getResult(command);
		} catch (Exception e1) {
			e1.printStackTrace();
		}

		ArrayList<String> trResult = new ArrayList<String>();
		trResult.add("a1a.txt - Sun Jan 08 18:48:02 MSK 2012 - C:\\TEST1\\111\\a1a.txt");
		trResult.add("a1b - Sun Jan 08 18:47:52 MSK 2012 - C:\\TEST1\\111\\a1b");
		trResult.add("a1b.txt - Sun Jan 08 18:48:02 MSK 2012 - C:\\TEST1\\111\\a1b.txt");

		assertEquals("Result", trResult, result.getData());
	}

	@Test
	public void testMask2() {
		init();
		String[] args = { "C:\\TEST1", "a***1*" };
		command.setNameCommand("find");
		command.setArgs(args);

		try {
			result = tester.getResult(command);
		} catch (Exception e1) {
			e1.printStackTrace();
		}

		ArrayList<String> trResult = new ArrayList<String>();
		trResult.add("a1a.txt - Sun Jan 08 18:48:02 MSK 2012 - C:\\TEST1\\111\\a1a.txt");
		trResult.add("a1b - Sun Jan 08 18:47:52 MSK 2012 - C:\\TEST1\\111\\a1b");
		trResult.add("a1b.txt - Sun Jan 08 18:48:02 MSK 2012 - C:\\TEST1\\111\\a1b.txt");

		assertEquals("Result", trResult, result.getData());
	}
}
